<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('业务员列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label style="width: 80px;">业务员名称：</label>
                                <input type="text" name="smName"/>
                            </li>
                            <li>
                                <label style="width: 80px;">业务员电话：</label>
                                <input type="text" name="smPhone"/>
                            </li>
                            <li>
                                <label>状态</label>
                                <select name="smStatus">
                                    <option value="">所有</option>
                                    <option value="0">正常</option>
                                    <option value="1">关闭</option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add(450,800)" >
                    <i class="fa fa-plus"></i> 添加
                </a>
               <!-- <a class="btn btn-primary single disabled" onclick="$.operate.edit(350,800)" >
                    <i class="fa fa-edit"></i> 修改
                </a>-->
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "salesman/salesman";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "业务员",
                clickToSelect:true,
                columns: [{
                    checkbox: true
                },
                {
                    field: 'smNum',
                    title: '业务员编号',
                    visible: false
                },
                {
                    field: 'smName',
                    title: '业务员名称'
                },
                {
                    field: 'smPhone',
                    title: '业务员电话'
                },
                {
                    field: 'smStatus',
                    title: '状态',
                    formatter:function(value,row,index){
                        return statusTools(row);
                    }
                },
                {
                    field: 'saleAgentNum',
                    title: '展业编号',
                },
                {
                    field: 'deduct',
                    title: '分成',
                },
                {
                    field: 'smAddtime',
                    title: '添加时间'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="$.operate.edit(\'' + row.smNum + '\',\'450\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs " href="javascript:void(0)" onclick="$.operate.remove(\'' + row.smNum + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });


        /* 业务员状态 */
        function statusTools(row) {
            if (row.smStatus == 0) {
                return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.smNum + '\')"></i> ';
            } else {
                return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.smNum + '\')"></i> ';
            }
        }

        /* 业务员-停用 */
        function disable(id) {
            $.modal.confirm("确认要禁用当前业务员吗？", function() {
                $.operate.post(prefix + "/edit", {"smNum": id,"smStatus": '1'});
            })
        }

        /* 业务员-启用 */
        function enable(id) {
            $.modal.confirm("确认要启用当前业务员吗？", function() {
                $.operate.post(prefix + "/edit", {"smNum": id,"smStatus": '0'});
            })
        }


    </script>
</body>
</html>